<?php


namespace console\controllers;

use console\components\daemons\task\Daemon;
use Yii;
use yii\console\Controller;
use yii\console\ExitCode;

class TaskController extends Controller
{

    /**
     * 是否为守护进程模式运行
     * @var bool
     */
    public $daemon = false;

    public function actionStart()
    {

        if(Daemon::start($this->daemon) === true)
        {
            return ExitCode::OK;
        }
        return ExitCode::UNSPECIFIED_ERROR;

    }

    public function options($actionID)
    {
        return array_merge(parent::options($actionID), ['daemon']);
    }


    /**
     * 关闭服务
     * @return int
     */
    public function actionStop()
    {
        Daemon::stop();

        return ExitCode::OK;
    }

}
